package com.woniuxy.exam.controller;

import com.woniuxy.commons.entity.PaperClassification;
import com.woniuxy.commons.entity.ResponseEntity;
import com.woniuxy.exam.service.PaperClassificationService;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 余枭春
 * @Date 2020/7/18 16:09
 * @Description:
 **/
@RestController
public class PaperClassificationController {
    @Autowired
    private PaperClassificationService paperClassificationService;

    @GetMapping("/paperClassification/all")
    public ResponseEntity<List<PaperClassification>> allPaperClassification() {
        return new ResponseEntity<>(200, "ok", paperClassificationService.allPaperClassification());
    }

    @PostMapping("/paperClassification/insert")
    public ResponseEntity<Integer> insertPaperClassification(@RequestBody PaperClassification paperClassification) {
        return new ResponseEntity<>(200, "ok", paperClassificationService.insertPaperClassification(paperClassification));
    }
    @PostMapping("/paperClassification/updateName")
    public ResponseEntity<Integer> updataPaperClassificationNameById(@RequestBody PaperClassification paperClassification) {
        return new ResponseEntity<>(200, "ok", paperClassificationService.updataPaperClassificationNameById(paperClassification));
    }
    @GetMapping("/paperClassification/delete/{id}")
    public ResponseEntity<Integer> deletePaperClassificationById(@PathVariable("id")int id) {
        int res=paperClassificationService.deletePaperClassificationById(id);
        if(res==-1){
            return new ResponseEntity<>(500, "没有该试卷分类", null);
        }
        return new ResponseEntity<>(200, "ok", null);
    }

}
